import 'package:flutter/material.dart';
import 'package:flutter/widgets.dart';

var CHARS = ['A', 'B', 'C', 'D', 'E', 'F', 'G', 'H', 'I', 'J', 'K',
'L', 'M', 'N', 'O', 'P', 'Q', 'R', 'S', 'T', 'U', 'V', 'W', 'X', 'Y', 'Z', '#'];

class CharIndexPainter extends CustomPainter{

  final double dotRadius;
  final double shadowWidth;
  final Color textSelectColor;
  final Color textUnSelectColor;
  final Color dotColor;
  CharIndexPainter({
    this.dotRadius,
    this.shadowWidth = 2.0,
    this.textUnSelectColor = Colors.black12,
    this.textSelectColor = const Color(0XFFFFFFF),
    this.dotColor = Colors.blueAccent,
  });
double offsetY = 3;
double offsetX = 8;
double height = 15;
double maxWidth = 15;
  @override
  void paint(Canvas canvas, Size size) {
    var newLine = false;
    Paint _paint = Paint()
      ..color = Colors.blueAccent //画笔颜色
      ..strokeCap = StrokeCap.round //画笔笔触类型
      ..isAntiAlias = true //是否启动抗锯齿
      ..blendMode = BlendMode.exclusion //颜色混合模式
      ..style = PaintingStyle.fill //绘画风格，默认为填充
      ..colorFilter = ColorFilter.mode(Colors.blueAccent,
          BlendMode.exclusion) //颜色渲染模式，一般是矩阵效果来改变的,但是flutter中只能使用颜色混合模式
      ..maskFilter = MaskFilter.blur(BlurStyle.inner, 3.0) //模糊遮罩效果，flutter中只有这个
      ..filterQuality = FilterQuality.high //颜色渲染模式的质量
      ..strokeWidth = 15.0; //画笔的宽度



    TextSpan span = new TextSpan(style: new TextStyle(fontSize: 13,color: textUnSelectColor), text:"A\nB\nC\nD\nE\nF");
    TextPainter tp = new TextPainter(
        text: span,
        textAlign: TextAlign.center,
        textDirection: TextDirection.ltr);
    tp.layout();
    if (offsetY + tp.height > height) { // 如果一列不够一个文字，就新起一列。
      newLine = true;
      offsetY = 0; // 如果是新起一列，y 从0 开始
    }

    if (newLine) {
      offsetX -= maxWidth;
      newLine = false;
    }

    if (offsetX < -maxWidth) {
     // break; // 如果超出左边边界，不绘制。
    }

    tp.paint(canvas, new Offset(offsetX, offsetY));
    offsetY += tp.height;
  }

  @override
  bool shouldRepaint(CustomPainter oldDelegate) {
    // TODO: implement shouldRepaint
    return true;
  }

}